package com.defan.api.utils;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by 张俊强~ on 2017/10/17.
 */
public final class ShowDocUtils {

    /**
     * The constant ApiKey.
     */
    public static final String ApiKey = "03e7f5484d28dae33eaa6632dce2aa0e1415336797";
    /**
     * The constant ApiToken.
     */
    public static final String ApiToken = "b1cc0e5117d359f29a582ea8ecc01c1675273261";

    /**
     * The constant ShowDocApi.
     */
    public static final String ShowDocApi = "https://www.showdoc.cc/server/api/item/updateByApi";
    public static final String ApiDocNote = "**备注**\n\n- ```添加当前接口所在pkg```\n\n";

    /**
     * 将接口信息发布到ShowDoc平台上去.
     *
     * @author 张俊强~
     * @param pageContent 页面内容
     * @param sNumber     the s number
     * @return the md result text
     * @throws IOException the io exception
     */
    public static String getMDResultText(String pageContent, String sNumber,String catName,String subCatName,String pageTitle) throws IOException {
        System.setProperty("javax.net.ssl.trustStore", "E:\\ApiAutoBuilder\\lib\\jssecacerts");

        Map requestParams = new HashMap();
        requestParams.put("api_key", ShowDocUtils.ApiKey);
        requestParams.put("api_token", ShowDocUtils.ApiToken);
        requestParams.put("cat_name", catName);
        requestParams.put("cat_name_sub", subCatName);
        requestParams.put("page_title", pageTitle);
        requestParams.put("page_content", pageContent);
        requestParams.put("s_number", sNumber);

        String responseResult = RequestUtils.getResponseMess(ShowDocApi, requestParams, null, null);
        return responseResult;

    }

    /**
     * Format to mardown string.
     *
     * @param map 包含所有信息的map
     * @return the string
     * @author 张俊强~
     */
    public static String formatToMardown(Map map){
        String result="";

        result+="**请求URL：** \n" +
                "- ` "+map.get("url")+" `\n" +
                "  \n" +
                "**请求方式：**\n" +
                "- "+map.get("method")+" \n" +
                "\n" +
                "**参数：** \n" +
                "\n" +
                map.get("param_str")+"\n" +
                "\n" +
                "**输入示例：** \n" +
                "``` \n" +
                map.get("param_json")+"\n" +
                "```\n" +
                "**返回示例**\n"+
                "``` \n"+
                map.get("result_text")+"\n" +
                "```\n"+
                "**返回参数说明**\n"+
                "\n" +
                map.get("result_table")+"\n" +
                "\n" +
                ApiDocNote;

        return result;
    }
}
